#pragma once
#include <emmintrin.h>

namespace FastMath
{
	__forceinline double Cos(const double iA)
	{
		__asm
		{
			fld iA
				fcos
		}
	}


	//---------------------------------------------------------------------------------------------------------------------------------------------
	__forceinline double Sin(const double iA)
	{
		__asm
		{
			fld iA
				fsin
		}
	}


	//---------------------------------------------------------------------------------------------------------------------------------------------
	inline void SinCos(double iA, double& oSin, double& oCos)
	{
		_asm
		{
			fld    iA
				fsincos
				mov    ecx, oCos
				mov    edx, oSin
				fstp  qword ptr [ecx]
			fstp  qword ptr [edx]
		}
	}

/*

	//---------------------------------------------------------------------------------------------------------------------------------------------
	inline double Sqrt(double iX)
	{
		__asm
		{
			fld iX
				fsqrt
		}
	}
*/


	//---------------------------------------------------------------------------------------------------------------------------------------------
	inline double Sqrt(double iX)
	{
		__m128d x = _mm_load_sd(&iX);
		x = _mm_sqrt_sd(x, x);
		double d;
		_mm_store_sd(&d, x);
		return d;
	}
}